<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp"%>
<!DOCTYPE html>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content">
		<div class="row">
			<div class="col-sm-12">

				<div class="ibox float-e-margins">
					<div class="ibox-content">
						<form class="form-horizontal m-t" id="dictForm">
							<input type="hidden" name="parentId" value="${parentId}">

							<div class="form-group">
								<label class="col-sm-3 control-label">类型编码：</label>
								<div class="col-sm-8">
									<input type="text" id="typeCode" class="form-control" name="typeCode">

								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">类型名称：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" name="typeName">
								</div>
							</div>
							<c:if test="${parentId ne '1' }">
								<div class="form-group">
									<label class="col-sm-3 control-label">数据值：</label>
									<div class="col-sm-8">
										<input type="text" class="form-control" name="typeValue">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">排序：</label>
									<div class="col-sm-8">
										<input type="number" class="form-control" min="1" max="50" name="sort">
									</div>
								</div>
							</c:if>

							<div class="form-group">
								<label class="col-sm-3 control-label">备注：</label>
								<div class="col-sm-8">
									<textarea class="form-control" name="remarks"> </textarea>
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-4 col-sm-offset-2">
									<shiro:hasPermission name="dict_add">
										<button class="btn btn-primary" type="submit">保存内容</button>
									</shiro:hasPermission>
								</div>
							</div>
						</form>

						<div align="center">
							<button class="btn btn-outline btn-danger" type="" id="closeIframe">关闭</button>
						</div>
					</div>
				</div>

			</div>
		</div>
	</div>
	<script type="text/javascript">
		var parentId = "${parentId}";
		$('#closeIframe').click(function() {
			closeParentWindow();
		});
		var flag = parentId == "" ? false : true;
		$().ready(function() {
			var e = "<i class='fa fa-times-circle'></i> ";
			$("#dictForm").validate({
				rules : {
					typeCode : {
						required : true,
						abc : true,
						minlength : 2,
						maxlength : 40
					},
					typeName : "required",
					typeValue : {
						required : flag
					},
					remarks : {
						maxlength : 255
					},
				},
				messages : {
					typeCode : e + "${fns:getErrorMessage('ERROR_DICT_TYPE_CODE')}",
					typeName : e + "${fns:getErrorMessage('ERROR_DICT_TYPE_NAME')}",
					remarks : e + "${fns:getErrorMessage('ERROR_REMARKS')}",
					typeValue : e + "${fns:getErrorMessage('ERROR_DICT_TYPE_VALUE')}"

				},
				submitHandler : function(form) {
					var data = formToJson("dictForm");
					$.post(basePath + "/dict/insert", data, function(data) {
						if (data.success) {
							succuceMsg(data.msg);
							if ("1" == parentId) {
								parent.$('#dictTree').jstree(true).refresh();
							}
							parent.$("#queryTable").bootstrapTable('refresh');

							delayCloseParentWindow();
						} else {
							errorMsg(data.msg);
						}
					}, "json");
				}
			});
		});
	</script>
</body>
</html>